package com.metaera.app.ui.activities;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.metaera.app.LocalConfigStore;
import com.metaera.app.R;
import com.metaera.app.ui.core.BaseActivity;
import com.metaera.app.utils.ActivityTitleHelper;
import com.metaera.app.utils.LoginClickListener;
import com.metaera.app.utils.event.LogoutEvent;
import com.umeng.analytics.MobclickAgent;

import org.greenrobot.eventbus.EventBus;


public class SettingActivity extends BaseActivity {

//    @Override
//    protected int getBackgroundColor() {
//        return Color.parseColor("#FAFAFA");
//    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_my_settings;
    }

    @Override
    protected void initialize(Bundle savedInstanceState) {
        ActivityTitleHelper.setTitle(this, R.string.my_setting_text);

        // find
        View exitButton = findViewById(R.id.fragment_me_exit_button);
        exitButton.setVisibility(LocalConfigStore.getInstance().isLogin() ? View.VISIBLE : View.GONE);

        // listener
        findViewById(R.id.layout_account_safe).setOnClickListener(new LoginClickListener(v ->
                startActivity(new Intent(this, AccountSafeActivity.class))));

        findViewById(R.id.rl_push_manager).setOnClickListener(
                new LoginClickListener(v -> startActivity(PushManagerActivity.class)));

        findViewById(R.id.fragment_me_grade_layout).setOnClickListener(v -> {
            try {

//                Uri uri = Uri.parse("market://details?id=com.tencent.mobileqq");
                Uri uri = Uri.parse("market://details?id=" + v.getContext().getPackageName());
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } catch (Exception e) {
                Toast.makeText(SettingActivity.this, "您的手机没有安装Android应用市场", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        });

        exitButton.setOnClickListener(v -> {
            MobclickAgent.onProfileSignOff();
            LocalConfigStore.getInstance().logout();
            EventBus.getDefault().post(new LogoutEvent());
            startActivity(new Intent(this, MainActivity.class));
        });
    }

//    @Override
//    public void onClick(View view) {
//        if (view.getId() == R.id.layout_account_safe) {
//            startActivity(new Intent(this, AccountSafeActivity.class));
//
//        }
////        else if (view.getId() == R.id.layout_mine_feedback) {
////            startActivity(new Intent(getContext(), FeedbackActivity.class));
////        }
//    }
}
